<template>
  <div class="playlists">
    <!-- 顶部导航栏 -->
    <navigation />

    <div class="container w">
      <div class="head">
        <h2>全部<i class="el-icon-arrow-down"></i></h2>

        <!-- 标签 -->
        <ul>
          <div>热门标签</div>
          <li v-for="(item, index) in Tags" :key="index">{{ item.name }}</li>
        </ul>

        <!-- 分类热门 -->
        <div class="rm">
          <span>热门</span>
          <span>最新</span>
        </div>
      </div>
      <ul class="box">
        <li
          v-for="(item, index) in songlist"
          :key="index"
          @click="change(item.id)"
        >
          <div class="pic">
            <img :src="item.coverImgUrl" alt="" />
            <span class="el-icon-caret-right">{{
              item.playCount | formatCount
            }}</span>
          </div>
          <span class="text">{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import navigation from "../../components/navigation/NaviGation";
import { Tags, songlist } from "../../network/index";
export default {
  name: "Playlist",
  data() {
    return {
      Tags: [],
      songlist: [],
    };
  },
  components: {
    navigation,
    songlist,
    Tags,
  },
  created() {
    // 获取歌单标签
    Tags().then((res) => {
      console.log(res);
      if (res.data.code == "200") {
        this.Tags = res.data.tags;
      }
    });
    // 获取歌单
    songlist().then((res) => {
      console.log(res);
      if (res.data.code == "200") {
        this.songlist = res.data.playlists;
      }
    });
  },
  methods: {
    change(id) {
      this.$router.push({
        //核心语句
        path: "/playlistitem", //跳转的路径
        query: {
          //路由传参时push和query搭配使用 ，作用时传递参数
          id: id,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.playlists {
  .container {
    margin-top: 110px;
    display: flex;
    flex-direction: column;
    .head {
      display: flex;
      justify-content: space-between;
      h2 {
        width: 90px;
        height: 40px;
        background-color: #fa2800;
        border-radius: 10px;
        text-align: center;
        line-height: 40px;
        font-size: 16px;
        color: #fff;
        i {
          padding-left: 10px;
        }
      }

      ul {
        display: flex;
        flex: 1;

        div {
          margin-left: 10px;
          width: 90px;
          height: 40px;
          line-height: 40px;
          text-align: center;
          font-size: 16px;
          font-weight: 700;
        }
        li {
          height: 40px;
          line-height: 40px;
          padding: 0 15px;
          text-align: center;
          font-size: 16px;
        }
      }
      .rm {
        width: 128px;
        height: 40px;
        line-height: 40px;
        font-size: 16px;
        span:nth-child(1) {
          background-color: #fa2800;
          padding: 5px 10px;
          border-radius: 10px;
          color: #fff;
          margin-right: 10px;
        }
        span:nth-child(2) {
          background-color: #f7f7f7;
          padding: 5px 10px;
          border-radius: 10px;
          color: #000;
          margin-right: 10px;
        }
      }
    }
    .box {
      display: flex;
      flex-wrap: wrap;
      li {
        width: 150px;
        // height: 160px;
        padding: 10px;

        // margin-bottom: 15px;
        .pic {
          position: relative;
          img {
            width: 100%;
            box-shadow: 10px 10px 10px #999;
            border-radius: 10px;
          }
          span {
            position: absolute;
            right: 10px;
            top: 10px;
            color: #fff;
            background-color: #000;
            padding: 5px;
            border-radius: 10px;
          }
        }
        .text {
          display: inline-block;
          // height: 25px;
          // line-height: 25px;
          font-size: 16px;
          font-weight: 700;
          padding-top: 10px;
        }
      }
    }
  }
}
</style>
